/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jps.main;

import jps.Interpreter.ASTVisitor;
import java.io.File;
import java.io.IOException;
import jps.Interpreter.Interpreter;
import jps.ast.*;
import jps.datastore.SBAStore;
import jps.envs.ENVS;
import jps.qres.QRESStack;
import org.jdom.JDOMException;

/**
 *
 * @author calyJa
 */
public class Main {

    public static final SBAStore sbaStore = new SBAStore();
    public static final QRESStack qres = new QRESStack();
    public static final ENVS envs = new ENVS();
    public static final ASTVisitor visitor = new Interpreter();

    public static void main(String[] args) throws JDOMException, IOException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException {

        String str = "data" + File.separator + "test_data.xml";
        sbaStore.loadXML(str);
        System.out.println(sbaStore.printStructure());

        envs.init(sbaStore.getRoot().getOID());

        //first expression - ((emp where fName = "Maciej").address.ulica)
        Expression ex1 = new DotExpression(
                new DotExpression(
                    new WhereExpression(
                        new NameExpression("emp"),
                        new EqualityExpression(
                            new NameExpression("fName"),
                            new StringTerminal("Maciej"))), 
                    new NameExpression("address")),
                new NameExpression("street"));
        ex1.accept(visitor);
        System.out.println("first expression - ((emp where fName = \"Maciej\").address.ulica) => " + qres.pop().toString());
        
        //second expression - ((emp where fName = "Maciej").address.ulica)
        Expression ex2 = new DotExpression(
                new WhereExpression(
                    new DotExpression(
                        new NameExpression("emp"),
                        new NameExpression("address")),                        
                    new EqualityExpression(
                        new NameExpression("number"),
                        new IntegerTerminal(50))), 
                new NameExpression("street"));
        ex2.accept(visitor);
        System.out.println("second expression - ((emp where fName = \"Maciej\").address.ulica) => " + qres.pop().toString());
        
    }
}